package com.buss.common;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jweb.core.bean.ReplyDataMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.buss.common.service.SysServiceI;


@Controller
public class TestController {
	
	@Autowired
	private SysServiceI sysService;

	@RequestMapping({ "/test.do" })
	public void test(HttpServletRequest request, HttpServletResponse response)
			throws IOException {
		System.out.println("test success");
	}
	
	@RequestMapping({ "/testjson.do" })
	@ResponseBody
	public ReplyDataMode serverList(HttpServletRequest req){
		ReplyDataMode j = new ReplyDataMode();

		List<Map> mapList = new ArrayList<Map>();
		Map map = null;
		String url = "1234";
		
		String sql = "SELECT NOW()";
		List<String> dataList = sysService.findListbySql(sql);
		String dataStr = "";  // 试卷id
		if(!dataList.isEmpty()){
			for(Object o : dataList){					
				dataStr = o.toString();
				System.out.println(dataStr);
				map=new HashMap();
				map.put("text", dataStr);
				map.put("href", url);
				mapList.add(map);
			}
		}
		
		Map resultMap = new HashMap();
		resultMap.put("list", mapList);
		Object obj = JSON.toJSON(resultMap);
		
		j.setData(obj);
		j.setSuccess(true);
		return j;
	}
	
}
